<?php

/*
 * File name : db_signUpCompany.php
* Description : Attaches the company information to the database.
* Created By : Abhiraj Chauhan
*/

include_once "basePage.php";

class db_signup extends basePage{

	public function signup()
	{
		$company_name = $_POST['company_name'];
		$company_address = $_POST['company_address'];
		$company_address_line= $_POST['company_address_line'];
		$company_city=$_POST['company_city'];
		$company_state=$_POST['company_state'];
		$company_zip=$_POST['company_zip'];
		$company_website=$_POST['company_website'];
		$company_contact_fname=$_POST['company_contact_fname'];
		$company_contact_lname=$_POST['company_contact_lname'];
		$company_contact_email=$_POST['company_contact_email'];
		$company_contact_phone=$_POST['company_contact_phone'];
		$company_contact_title=$_POST['company_contact_title'];
		
		$con = mysql_connect('localhost','pa_user','secret_password');
		if (!$con){
			die('Could not connect: ' . mysql_error());
		}
	
		mysql_select_db("TGS_GM_RESERVATION", $con);
			
		$result = mysql_query("SELECT CompanyName FROM TGS_GM_RESERVATION.tblcompany WHERE CompanyName = '{$_POST['company_name']}' AND CompanyZip = '{$_POST['company_zip']}'");
		$isExists=FALSE;
		while($row = mysql_fetch_array($result))
		{
			if ($row['CompanyName'] == $company_name){
			$isExists = TRUE;
			break;
			}
			else 
				$isExists = FALSE;
		}
		
		$result = mysql_query("SELECT CompanyID FROM TGS_GM_RESERVATION.tblcompany");
		while($row = mysql_fetch_array($result)){
			$company_id = $row['CompanyID'] + 1;
		}
		
		if (!($isExists)){
			$isUpdated=FALSE;
			$isUpdated = mysql_query("INSERT INTO TGS_GM_RESERVATION.tblcompany(CompanyID, CompanyName ,CompanyAddress, CompanyAddressLine,CompanyCity,CompanyState, CompanyZip, CompanyWebsite, CompanyContactFname, CompanyContactLname, CompanyContactEmail, CompanyContactPhone, CompanyContactTitle) VALUES ('{$company_id}','{$company_name}', '{$company_address}','{$company_address_line}','{$company_city}','{$company_state}','{$company_zip}','{$company_website}','{$company_contact_fname}','{$company_contact_lname}','{$company_contact_email}','{$company_contact_phone}','{$company_contact_title}')");
			//$result = mysql_query("SELECT CompanyName FROM TGS_GM_RESERVATION.tblcompany WHERE CompanyName = '$company_name'");
		}
		else
		{
			$isUpdated=FALSE;
			echo "<h2>Company Already Exists</h2>";
		}
	
		if ($isUpdated)
			echo "<h2>Sign Up Successful.</h2>";
		else
			echo "<h2>Sign Up Not Successful</h2>";
		
		mysql_close($con);
	}
}

$page= new db_signup();
$page->header();
$page->include_transalte();
$page->top_menu_company();
$page->signup();
$page->footer();
?>